﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefMeterDevice" :model="stateMeterDevice.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DeviceCode_FormItem" prop="Entity.DeviceCode" :label="$t('message.autotrans._Model_MeterDevice_DeviceCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_DeviceCode')}), trigger: 'blur' }]" >
            <el-input v-model="stateMeterDevice.vmModel.Entity.DeviceCode" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DeviceName_FormItem" prop="Entity.DeviceName" :label="$t('message.autotrans._Model_MeterDevice_DeviceName')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_DeviceName')}), trigger: 'blur' }]" >
            <el-input v-model="stateMeterDevice.vmModel.Entity.DeviceName" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DeviceType_FormItem" prop="Entity.DeviceType" :label="$t('message.autotrans._Model_MeterDevice_DeviceType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_DeviceType')}), trigger: 'blur' }]" >
            <el-select v-model="stateMeterDevice.vmModel.Entity.DeviceType" disabled clearable>
               <el-option key="ElectricMeter" value="ElectricMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ElectricMeter')"></el-option>
               <el-option key="PressureMeter" value="PressureMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_PressureMeter')"></el-option>
               <el-option key="FlowMeter" value="FlowMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_FlowMeter')"></el-option>
               <el-option key="ProtectiveGasMeter" value="ProtectiveGasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ProtectiveGasMeter')"></el-option>
               <el-option key="GasMeter" value="GasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_GasMeter')"></el-option>
               <el-option key="WaterMeter" value="WaterMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_WaterMeter')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Location_FormItem" prop="Entity.Location" :label="$t('message.autotrans._Model_MeterDevice_Location')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.Location" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Area_FormItem" prop="Entity.Area" :label="$t('message.autotrans._Model_MeterDevice_Area')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.Area" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Manufacturer_FormItem" prop="Entity.Manufacturer" :label="$t('message.autotrans._Model_MeterDevice_Manufacturer')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.Manufacturer" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_InstallDate_FormItem" prop="Entity.InstallDate" :label="$t('message.autotrans._Model_MeterDevice_InstallDate')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.InstallDate" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CommAddress_FormItem" prop="Entity.CommAddress" :label="$t('message.autotrans._Model_MeterDevice_CommAddress')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.CommAddress" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CommProtocol_FormItem" prop="Entity.CommProtocol" :label="$t('message.autotrans._Model_MeterDevice_CommProtocol')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_CommProtocol')}), trigger: 'blur' }]" >
            <el-select v-model="stateMeterDevice.vmModel.Entity.CommProtocol" disabled clearable>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Status_FormItem" prop="Entity.Status" :label="$t('message.autotrans._Model_MeterDevice_Status')">
            <el-select v-model="stateMeterDevice.vmModel.Entity.Status" disabled clearable>
               <el-option key="Normal" value="Normal" :label="$t('message.autotrans._Enum_EquipStatusEnum_Normal')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark" :label="$t('message.autotrans._Model_MeterDevice_Remark')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.Remark" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateTime_FormItem" prop="Entity.CreateTime" :label="$t('message.autotrans._Model_MeterDevice_CreateTime')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.CreateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateTime_FormItem" prop="Entity.UpdateTime" :label="$t('message.autotrans._Model_MeterDevice_UpdateTime')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.UpdateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateBy_FormItem" prop="Entity.CreateBy" :label="$t('message.autotrans._Model_MeterDevice_CreateBy')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.CreateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateBy_FormItem" prop="Entity.UpdateBy" :label="$t('message.autotrans._Model_MeterDevice_UpdateBy')">
            <el-input v-model="stateMeterDevice.vmModel.Entity.UpdateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <WtmTable ref="tableRefMeterParameterDeviceList2" v-bind="tableDataMeterParameterDeviceList2" v-model="stateMeterDevice.vmModel.Entity.MeterParameter_Device" disabled></WtmTable>
      <div style="text-align:right;">
        <WtmButton @click="onCloseMeterDevice"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageIoTManagementMeterDeviceDetails;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { meterdeviceApi } from '/@/api/iotmanagement/meterdevice';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const tableRefMeterParameterDeviceList2 = ref();
const tableDataMeterParameterDeviceList2 = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page参数名称'),key: 'ParamName',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page参数地址'),key: 'ParameterAddress',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page数据类型'),key: 'ParameterDataType',type: 'combobox',comboData:{
                Sys_Bit:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Bit'),
                Sys_Byte:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Byte'),
                Sys_Word:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Word'),
                Sys_DWord:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DWord'),
                Sys_Int:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Int'),
                Sys_DInt:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DInt'),
                Sys_Real:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Real')},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page参数单位'),key: 'ParamUnit',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page参数说明'),key: 'Description',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.SysEnable'),key: 'Eanble',type: 'combobox',comboData:
                {true:ci.proxy.$t('message._system.common.vm.tips_bool_true'),
                  false:ci.proxy.$t('message._system.common.vm.tips_bool_false')},isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: false, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
        isSub:true,
        isDisabled:true
	}
});

// 定义变量内容
const formRefMeterDevice = ref();
const stateMeterDevice = reactive({
    vmModel: {
	  Entity:{
        DeviceCode: '',
        DeviceName: '',
        DeviceType: undefined,
        Location: '',
        Area: '',
        Manufacturer: '',
        InstallDate: undefined,
        CommAddress: '',
        CommProtocol: undefined,
        Status: undefined,
        Remark: '',
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
        MeterParameter_Device:[],
        ID:null,
      },

	},
    
    AllDevices: [] as any[],
});

// 取消
const onCloseMeterDevice = () => {
    closeDialog();
};

// 提交
const onSubmitMeterDevice = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefMeterDevice.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            meterdeviceApi().edit(stateMeterDevice.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/IoTManagement/MeterParameter/GetMeterDevices',[],false).then(x=>{stateMeterDevice.AllDevices = x});
    if (ci.attrs["wtmdata"]) {
		stateMeterDevice.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateMeterDevice.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	meterdeviceApi().get(stateMeterDevice.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateMeterDevice.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

